<?php

declare(strict_types=1);

namespace App\Fastapp\Model;

use Hyperf\Database\Model\Relations\HasOne;
use Mine\MineModel;

/**
 * @property int $id 主键
 * @property int $user_id 用户id
 * @property int $parent_id 上级id
 * @property string $link 链条
 * @property \Carbon\Carbon $created_at 创建时间
 * @property int $status
 * @property-read null|Account $account
 */
class AccountInviteLevel extends MineModel
{
    public const UPDATED_AT = null;
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'account_invite_level';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'user_id', 'parent_id', 'link', 'created_at', 'status'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'user_id' => 'integer', 'parent_id' => 'integer', 'created_at' => 'datetime', 'status' => 'integer'];

    public function account(): HasOne
    {
        return $this->hasOne(Account::class, 'gene_id', 'user_id');
    }

    public function parent(): HasOne
    {
        return $this->hasOne(Account::class, 'gene_id', 'parent_id');
    }

    public function isRecharge(): HasOne
    {
        return $this->hasOne(AccountRecharge::class, 'user_id', 'user_id')
            ->where(['status' => 1])->groupBy('user_id')->select(['user_id']);
    }
}
